<template>
	<view>
		<carHeader :title="'已完成订单'"></carHeader>
		<view class="top">
			<view class="top-top">
				<view class="top-one">
					订单信息
					<view class="success">
						已完成
					</view>
				</view>
				<view class="top-two">
					<p>订单号：{{orderNum}}</p>
					<p>服务项目：{{orderName}}</p>
					<p>服务门店：{{orderShop}}
						<image src="../../static/车联网服务商家端-06维修任务-详情1_slices/plane.png"></image>
					</p>
					<p>下单时间：{{fromTime}}</p>
					<p>预约时间：{{toTime}}</p>
					<p>车辆：{{orderCar}}/{{yhclCarNum}}</p>
					<p>备注：{{orderBei}}</p>
				</view>
			</view>
			<view class="top-center">
				<view class="center-one">
					订单详情
				</view>
				<view class="center-two">
					<p><span>{{name}}</span>
						<span><span v-if="useMoney > 0">￥</span>{{useMoney}}</span>
					</p>
					<p><span>车辆附加费用</span>
						<span><span v-if="otherMoney > 0">￥</span>{{otherMoney}}</span>
					</p>
				</view>
				<view class="center-three">
					<p><span>原价</span>
						<span><span v-if="fisrtMoney > 0">￥</span>{{fisrtMoney}}</span>
					</p>

				</view>
				<view class="center-four">
					<p><span>优惠券</span>
						<span class="money1"><span v-if="coupon >= 0">-￥</span>{{coupon}}</span>
					</p>
				</view>
				<view class="center-five">
					<p><span>支付金额</span>
					                                                       <!-- 使用toFixed(2)来保留两位小数 -->
						<span class="money2"><span
								v-if="(fisrtMoney - coupon) > 0">￥</span>{{(fisrtMoney - coupon).toFixed(2)}}</span>
					</p>
				</view>
			</view>

		</view>
		<view class="bottom">
			<view class="bottom-top">
				评价结果
			</view>
			<view class="bottom-bottom">
				<p>评价时间：{{assesTime}}</p>
				<p>评价结果：
					<view class="star" v-for="(i,index) in 5" :key="index">
						<u-icon name="star-fill" color="#ffc100" v-if="index < assesEnd"></u-icon>
						<u-icon name="star-fill" color="#bfbfbf" v-if="index >= assesEnd"></u-icon>
					</view>
				</p>
				<p>评语：{{assesMessage}}</p>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item:{},
				ddNumber: '', // 用于存储接收到的ID  
				detailData: null, // 用于存储根据ID查询到的数据 
				orderNum: "",
				orderName: "",
				orderShop: "",
				fromTime: "",
				toTime: "",
				orderCar: "",
				yhclCarNum:"",
				orderBei: "",
				name:"",
				/* 项目花费价格 */
				useMoney:null,
				/* 附加费用 */
				otherMoney: null,
				/* 原价 */
				fisrtMoney: null,
				/* 店家优惠 */
				// reduceMoney: 20,
				/* 优惠券 */
				coupon: null,
				/* 评价时间 */
				assesTime: "",
				/* 评价结果 */
				assesEnd: null,
				/* 评语 */
				assesMessage: ""
			}
		},
		created() {
		
		},
		onLoad(options) {  
		    // options是页面跳转所带来的参数  
		    this.ddNumber = options.ddNumber; // 获取ID  
			// console.log(options.ddNumber); 
			console.log(this.ddNumber); 
		    this.successOrder(); // 调用方法查询数据  
		}, 
		methods: {
          successOrder(){
			uni.request({
				url: 'http://localhost:9299/dingdan/ddNumber/' + this.ddNumber,   // 你的接口地址  
				method: 'GET', // 或者 'POST'  
				// 如果是POST请求，data字段用来发送请求参数  
				// data: {  
				//   key: 'value'  
				// },  
				// 设置请求的 header  
				header: {  
				  'content-type': 'application/json' // 根据需要设置  
				  // 'Authorization': 'Bearer ' + token // 示例：添加token到header中  
				},  
				success: (res) => {  
				  // 请求成功的回调  
				  console.log('请求成功：', res.data.data);
				  if( res.data.data.sjyouhuiList[0].sjyhTriggerMoney > 0 ){
					  this.coupon = res.data.data.sjyouhuiList[0].sjyhPreferentialMoney;
				  }else{
					  this.coupon = 0;
				  }
				  
				  this.orderNum = res.data.data.ddNumber; 
				  this.orderName = res.data.data.serviceSortList[0].ssName; 
				  this.orderShop = res.data.data.shop.shopName; 
			      this.fromTime = res.data.data.ddAddtime;
				  this.toTime = res.data.data.ddYuyueTime;
				  this.orderCar = res.data.data.yonghucheliang.yhclType;
                  this.yhclCarNum = res.data.data.yonghucheliang.yhclCarNum;
			      this.orderBei = res.data.data.ddNote;
                  this.useMoney = res.data.data.serviceItemsList[0].oldPrice;
				  this.otherMoney = res.data.data.serviceItemsList[0].siExtraCharge;
				  this.fisrtMoney = res.data.data.serviceItemsList[0].totalPrices;
				  this.name = res.data.data.serviceItemsList[0].name; 
                  this.assesTime = res.data.data.evaluate.evTime; 
                  this.assesEnd = res.data.data.evaluate.evRate; 
                  this.assesMessage = res.data.data.evaluate.evContent; 
                  

				  // 假设后端返回的数据可以直接赋值给data  
				},  
				fail: (err) => {  
				  // 请求失败的回调  
				  console.error('请求失败：', err);  
				}  
			  }); 
		  }
		}
	}
</script>

<style lang="scss">
	.top {
		position: relative;
		top:-240rpx;
		background-color: #fff;
		border-radius: 50rpx;
		margin: 0 20rpx 20rpx;
		padding: 30rpx;

		.top-top {
			padding: 10rpx;

			.top-one {
				padding-bottom: 20rpx;
				font-size: 36rpx;
				border-bottom: 5rpx solid #f5f5f5;

				.success {
					display: inline-block;
					color: #f00;
					font-size: 24rpx;
					position: relative;
					left: 380rpx;
				}
			}

			.top-two {
				margin-top: 20rpx;
				font-size: 24rpx;
				margin-bottom: 40rpx;

				image {
					margin-left: 20rpx;
					width: 20rpx;
					height: 20rpx;
				}

				p {
					margin-top: 10rpx;
				}
			}
		}

		.top-center {
			padding: 10rpx;

			p {
				margin-top: 15rpx;
				display: flex;
				justify-content: space-between;
			}

			.center-one {
				font-size: 36rpx;
				padding-bottom: 20rpx;
				font-size: 36rpx;
				border-bottom: 5rpx solid #f5f5f5;

			}

			.center-two {
				margin: 20rpx 0;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #f5f5f5;
			}

			.center-three {
				margin: 20rpx 0;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #f5f5f5;

				.money1 {
					color: #f00;
				}
			}

			.center-four {
				margin: 20rpx 0;
				padding-bottom: 20rpx;
				border-bottom: 5rpx solid #f5f5f5;

				.money1 {
					color: #f00;
				}
			}

			.center-five {
				margin: 20rpx 0;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #f5f5f5;

				.money2 {
					font-weight: 550;
					font-size: 36rpx;
				}
			}
		}
	}

	.bottom {
		position: relative;
		top:-230rpx;
		background-color: #fff;
		border-radius: 50rpx;
		margin: 0 20rpx 20rpx;
		padding: 30rpx;
		
		.bottom-top {

			font-size: 36rpx;
			padding-bottom: 20rpx;
			font-size: 36rpx;
			border-bottom: 5rpx solid #f5f5f5;

		}

		.bottom-bottom {
			margin-top: 20rpx;
			p {
				margin-top: 15rpx;
			}
			.star {
				display: inline-block;
			}
		}
	}
</style>